<?php

/**
 * categoria actions.
 *
 * @package    tvpv
 * @subpackage categoria
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 8507 2008-04-17 17:32:20Z fabien $
 */
class categoriaActions extends sfActions
{
  public function executeIndex()
  {
  	$pager = new sfPropelPager('Categoria',20);
  	$pager->setCriteria(new Criteria());
  	$pager->init();
  	
    //$this->categoriaList = CategoriaPeer::doSelect(new Criteria());
    $this->categoriaList = $pager;
  }

  public function executeCreate()
  {
    $this->form = new CategoriaForm();

    $this->setTemplate('edit');
  }

  public function executeEdit($request)
  {
    $this->form = new CategoriaForm(CategoriaPeer::retrieveByPk($request->getParameter('id')));
  }

  public function executeUpdate($request)
  {
    $this->forward404Unless($request->isMethod('post'));

    $this->form = new CategoriaForm(CategoriaPeer::retrieveByPk($request->getParameter('id')));

    $this->form->bind($request->getParameter('categoria'));
    if ($this->form->isValid())
    {
      $categoria = $this->form->save();

      $this->redirect('categoria/index');
    }

    $this->setTemplate('edit');
  }

  public function executeDelete($request)
  {
    $this->forward404Unless($categoria = CategoriaPeer::retrieveByPk($request->getParameter('id')));

    $categoria->delete();

    $this->redirect('categoria/index');
  }
  
  public function executeSetNombre($request)
  {
  	$categoria = CategoriaPeer::retrieveByPK($request->getParameter('id'));
  	$categoria->setNombre($request->getParameter('value'));
  	$categoria->save();
  	return $this->renderText($request->getParameter('value'));
  }
}
